import java.util.Arrays;

public class TestSort {

    public  static void insertSort(int[] array){
        for (int i = 1; i < array.length; i++) {
            int tmp = array[i];
            int j = i-1;
            for (; j >= 0; j--) {
                if (array[j] > tmp){
                    array[j+1] = array[j];
                }else {
                    break;
                }
            }
            array[j+1] = tmp;
        }
    }

    public static void shell(int[] array, int gap){
        for (int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i-gap;
            for (; j >= 0 ; j -= gap) {
                if (array[j] > tmp){
                    array[j+gap] = array[j];
                }else {
                    break;
                }

            }
            array[j+gap] = tmp;
        }
    }

    public static void shellSort1(int[] array){
        int gap = array.length;
        while (gap > 1){
            shell(array, gap);
            gap /= 2;
        }
        shell(array,1);
    }

    public static void shellSort(int[] array){
        int[] drr = {5,3,1};
        for (int i = 0; i < drr.length; i++) {
            shell(array,drr[i]);
        }
    }

    public static void swap(int[] array, int i, int j){
        int tmp = array[i];
        array[i] = array[j];
        array[j] = tmp;
    }

    public static void selectSort1(int[] array){
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if (array[j] < array[i]){
                    swap(array,i,j);
                }
            }
        }
    }

    public static void selectSort(int[] array){
        for (int i = 0; i < array.length; i++) {
            int min = i;
            for (int j = i+1; j < array.length; j++) {
                if (array[j] < array[min]){
                    min = j;
                }
            }
            swap(array,i,min);
        }
    }

    public static void main(String[] args) {
        int[] array = {10,5,6,2,1};
        selectSort(array);
        System.out.println(Arrays.toString(array));

    }
}
